#include <bits/stdc++.h>
#define ll long long
#define isok cout << "ok" << endl
#define db(s,a) cout << s << ":" << a << endl
#define dbarr(a,n) for(ll i=1;i<=n;i++) cout << a[i] << " " ; cout << endl
#define read(n) scanf("%lld",&n)
#define write(n) printf("%lld\n",n)
using namespace std ;
ll tt , n , i , pre1 , pre2 , maxx , tot , a[200005] , t[200005] ;
bool vis[200005] , b[200005] ;
set<ll> s ;
void dfs(ll dep){
    if(dep>tot){
        pre1 = -1 ;
        pre2 = -1 ;
        ll cnt = 0 ;
        for(ll i=1;i<=tot;i++){
            b[t[i]] = vis[i] ;
        }
        for(ll i=1;i<=n;i++){
            if(b[a[i]]){
                if(pre1==-1){
                    pre1 = i ;
                }else {
                    if(a[i]==a[pre1]){
                        cnt += a[i] ;
                    }
                    pre1 = i ;
                }
            }else {
                if(pre2==-1){
                    pre2 = i ;
                }else {
                    if(a[i]==a[pre2]){
                        cnt += a[i] ;
                    }
                    pre2 = i ;
                }
            }
        }
        maxx = max(maxx,cnt) ;
        return ;
    }
    vis[dep] = true ;
    dfs(dep+1) ;
    vis[dep] = false ;
    dfs(dep+1) ;
}
int main(){
    freopen("color.in","r",stdin) ;
    freopen("color.out","w",stdout) ;
    read(tt) ;
    while(tt--){
        read(n) ;
        maxx = -1 ;
        s.clear() ;
        for(i=1;i<=n;i++){
            read(a[i]) ;
            s.insert(a[i]) ;
        }
        if(s.size()==n){
            write(0LL) ;
            continue ;
        }
        for(auto &&k : s){
            t[++tot] = k ;
        }
        dfs(1) ;
        write(maxx) ;
    }
    return 0 ;
}
